package com.yoomiito.app.ui.my.remain.transfer;

import com.yoomiito.app.base.AppConfig;
import com.yoomiito.app.base.BaseLazyFragmentPresenter;
import com.yoomiito.app.model.my.PayeeInfo;
import com.yoomiito.app.net.YmApi;

import cn.droidlover.xdroidmvp.net.ApiException;
import cn.droidlover.xdroidmvp.net.ApiSubscriber;
import cn.droidlover.xdroidmvp.net.XApi;

public class InputTelPresenter extends BaseLazyFragmentPresenter<InputTelFragment> {
    public InputTelPresenter(AppConfig appConfig) {
        super(appConfig);
    }

    public void getInfo(String mobile){
        YmApi.getYmService()
                .getPayeeInfo(mobile)
                .compose(getV().bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(new ApiSubscriber<PayeeInfo>() {
                    @Override
                    public void onSuccess(PayeeInfo payeeInfo) {
                        if (hasV()){
                            getV().payeeInfo(payeeInfo);
                        }
                    }

                    @Override
                    public void onFail(ApiException error) {
                        if (error.getCode()==ApiException.MOBILE_RIGHT){
                            getV().showTip("账号不存在","请确认手机号码是否正确","确认");
                        }
                    }
                });
    }
}
